package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.ProductSkuVo;
import com.spzx.product.api.domain.SkuPriceVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * ClassName: RemotrProductFallbackFactory
 * Package: com.spzx.product.api.factory
 * Description:
 *
 * @Author 王颖轩
 * @Create 2024/12/29 17:58
 * @Version 1.0
 */

@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    @Override
    public RemoteProductService create(Throwable throwable) {
        //兜底结果
        return new RemoteProductService() {
            @Override
            public R<SkuPriceVo> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品sku价格失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SkuPriceVo>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("批量查询商品实时价格失败:" + throwable.getMessage());
            }

            @Override
            public R<ProductSkuVo> getProductSkuVo(Long skuId, String source) {
                return R.fail("获取商品sku失败:" + throwable.getMessage());
            }
        };
        //将以上代码改成lamda的版本
        /* return (skuId, source) -> R.fail("获取商品sku失败:" + throwable.getMessage());*/
    }
}

